package com.lovo.service.serviceImpl;

import com.lovo.bean.Goods;
import com.lovo.dao.GoodsMapper;
import com.lovo.service.IGoodsService;
import com.lovo.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class GoodsServiceImpl implements IGoodsService {
    @Override
    public List<Goods> getAll() {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodsMapper mapper = sqlSession.getMapper(GoodsMapper.class);
        List<Goods> list = mapper.getAll();
        SqlSessionUtil.commit();
        return list;
    }

    @Override
    public boolean GoodsAdd(Goods goods) {

        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodsMapper mapper = sqlSession.getMapper(GoodsMapper.class);
        int i = mapper.GoodsAdd(goods);
        SqlSessionUtil.commit();
        return i>0? true:false;
    }

    @Override
    public boolean deleteById(Integer goodsId) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodsMapper mapper = sqlSession.getMapper(GoodsMapper.class);
        int i = mapper.deleteById(goodsId);
        SqlSessionUtil.commit();
        return i>0? true:false;
    }

    @Override
    public Goods selectById(Integer goodsId) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodsMapper mapper = sqlSession.getMapper(GoodsMapper.class);
        Goods goods = mapper.selectById(goodsId);
        SqlSessionUtil.commit();
        return goods;
    }

    @Override
    public boolean updateByPrimaryKeySelective(Goods goods) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodsMapper mapper = sqlSession.getMapper(GoodsMapper.class);
        int i = mapper.updateByPrimaryKeySelective(goods);
        SqlSessionUtil.commit();
        return i>0? true:false;
    }
}
